//
//  QDTMainPageCycleTableViewCell.m
//  QDMetroClient
//
//  Created by YueWen on 2019/1/31.
//  Copyright © 2019 YueWen. All rights reserved.
//

#import "QDMPTopCycleTableViewCell.h"
#import "RITLEllipseCycleScrollView.h"
#import "EllipsePageControl+ItemControl.h"
#import "RITLCollectionViewPageFlowLayout.h"
#import "QDMetroClient-Swift.h"


CGFloat QDMainPageCycleTopTableViewCellHeight(void) {
    
    CGFloat scale = 160.0 / 335;
    CGFloat itemWidth = UIScreen.mainScreen.ritl_width - 20 - 20;
    return (NSInteger)ceil(itemWidth * scale);
}


@interface QDMPTopCycleTableViewCell()<RITLEllipseCycleScrollViewPageConfiguration,RITLSDCycleScrollViewDataSource>

/// 轮播视图
@property (nonatomic, strong) RITLEllipseCycleScrollView *cycleView;

@end

@implementation QDMPTopCycleTableViewCell

@synthesize cycleView = _cycleView;


#pragma mark - Super


- (RITLSDCycleScrollView *)cycleView {
    
    if (!_cycleView) {
        
        RITLEllipseCycleScrollView *cycleView = RITLEllipseCycleScrollView.new;
        cycleView.configuration = self;
        cycleView.dataSource = self;
        cycleView.delegate = self;
        cycleView.pageEnable = false;
        cycleView.infiniteLoop = true;
        cycleView.autoScroll = true;
        cycleView.imageURLStringsGroup = @[@"",@"",@""];
        
        cycleView.pageControlMarginRight = 33;
        cycleView.pageControlMarginBottom = 7;
        cycleView.el_pageControl.controlSize = 5;
        cycleView.el_pageControl.scale = 20 / 5;

        _cycleView = cycleView;
    }
    return _cycleView;
}



- (UIEdgeInsets)cycleContentInsets {
    return UIEdgeInsetsMake(0, 0, 0, 0);
}


#pragma mark - <RITLEllipseCycleScrollViewPageConfiguration>

- (void)ritlEllipseCycleScrollViewConfiguratePageControl:(RITLEllipseCycleScrollView *)view {
    
    view.el_pageControl.currentColor = UIColor.whiteColor;
    view.el_pageControl.otherColor = [UIColor.whiteColor colorWithAlphaComponent:0.4];
}


- (BOOL)ritlEllipseCycleScrollViewConfiguratePageControlIsMiddle:(RITLEllipseCycleScrollView *)view {
    return false;
}


#pragma mark - <RITLSDCycleScrollViewDataSource>

- (void)cycleView:(RITLSDCycleScrollView *)cycleView setupCustomCell:(UICollectionViewCell<RITLSDCycleScrollViewCell> *)cell forIndex:(NSIndexPath *)indexPath {
    
    if (self.customHandler) { self.customHandler(cycleView, cell, indexPath); }
}


- (UICollectionViewFlowLayout *)customFlowLayout:(RITLCollectionViewPageFlowLayout *)originFlowLayout {
    
    return [originFlowLayout ritl_mutable:^id _Nonnull(__kindof RITLCollectionViewPageFlowLayout  * _Nonnull flowLayout) {
        
        CGFloat scale = 160.0 / 335;
        CGFloat itemWidth = UIScreen.mainScreen.ritl_width - 20 - 20;
        flowLayout.itemSize = CGSizeMake(itemWidth, itemWidth * scale);
        
        return flowLayout;
    }];
}


//- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
//    
//    if (self.selectHandler) {
//        self.selectHandler(cycleScrollView, index);
//    }
//}

@end
